package cn.wolfcode.education.web.controller;

import cn.wolfcode.education.domain.Employee;
import cn.wolfcode.education.service.IEmployeeService;
import cn.wolfcode.education.util.JSONResult;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 修改密码
 */
@Controller
@RequestMapping("changePassword")
public class ChangePasswordController {
    @Autowired
    private IEmployeeService employeeService;

    //登陆  定位到登录页面
    @RequestMapping("changePassword")
    public String retrieve() {
        System.out.println("***************修改密码页面定位*************");
        return "changePassword";
    }
    //修改密码
    @RequestMapping("updatepassword")
    @ResponseBody
    public JSONResult updatepassword(String newPassword) {
        JSONResult jsonResult = new JSONResult();
        System.out.println("***************修改密码操作*************");
        if (newPassword == null) {
            jsonResult.setMsg("密码不能为空");
        }
        Employee employee1 = (Employee) SecurityUtils.getSubject().getPrincipal();
        employeeService.updatePassword(employee1.getUsername(),newPassword);
        return jsonResult;
    }
}
